jQuery.fn.extend({
    filterRender: function() {
        return this.each(function() {
            $(this).empty(), new jQuery.Filter(this);
        });
    }
}), jQuery.Filter = function(obj) {
    function setupHidden() {
        var a = document.createElement("input"), b = $(a);
        return b.attr("type", "hidden"), null != $select.attr("name") && b.attr("name", $select.attr("name")), 
        b;
    }
    function createGroup(a, b) {
        var c, d, e, f, g, h, i, j;
        if (multiMode = !0, c = 100, $select.attr("groupTitleWidth") && (c = Number($select.attr("groupTitleWidth"))), 
        d = $('<table class="filterTable"></table>'), e = b[dataRoot] ? b[dataRoot] : b, 
        $.each(e, function(a, b) {
            var g, e = $("<tr></tr>"), f = $('<td class="left"></td>');
            f.text(b.name), f.width(c), g = $('<td class="right"></td>'), createOptions(g, b[dataRoot]), 
            e.append(f), e.append(g), d.append(e);
        }), a.append(d), "-1" != selectedValue) {
            if (f = "", g = "", 1 == selectionStay) $select.find("li").each(function() {
                $(this).attr("id") == selectedValue && ($(this).addClass("nocloseCurrent"), f = $(this).attr("id"), 
                g = $(this).text());
            }); else {
                for (h = selectedValue.split(","), i = 0; i < h.length; i++) $select.find("li").each(function() {
                    $(this).attr("id") == h[i] && ($(this).addClass("current"), f = f + $(this).attr("id") + ",", 
                    g = g + $(this).text() + ",");
                });
                f.length > 0 && (f = f.substring(0, f.length - 1)), g.length > 0 && (g = g.substring(0, g.length - 1));
            }
            $select.attr("relText", g), $select.attr("relValue", f), $hidden.val(f);
        } else 1 == selectionStay ? (j = $select.find("li").eq(0), j.addClass("nocloseCurrent"), 
        $select.attr("relText", j.text()), $select.attr("relValue", j.attr("id")), $hidden.val(j.attr("id"))) : ($select.attr("relText", ""), 
        $select.attr("relValue", ""), $hidden.val(""));
    }
    function createOptions(a, b) {
        var d, e, f, g, h, i, c = $("<ul></ul>");
        if (a.append(c), $select.append($hidden), b) {
            if (d = b[dataRoot] ? b[dataRoot] : b, $.each(d, function(a, b) {
                var d;
                selectionStay ? (d = $("<li></li>"), d.html(b.key)) : (d = $('<li><a class="textSlice"></a></li>'), 
                d.find("a").each(function() {
                    var a;
                    b.iconClass ? (a = $("<span></span>"), a.addClass(b.iconClass), a.html(b.key), $(this).append(a)) : b.iconSrc ? (a = $("<span></span>"), 
                    a.css({
                        backgroundImage: "url(" + b.iconSrc + ")",
                        backgroundRepeat: "no-repeat",
                        backgroundPosition: "0 50%",
                        display: "block",
                        paddingLeft: "18px"
                    }), a.html(b.key), $(this).append(a)) : $(this).html(b.key), 1 == showTip ? ($(this).attr("title", b.key), 
                    $(this).attr("keepDefaultStyle", "true")) : 1 == showInfo && $(this).attr("title", b.key), 
                    $(this).css({
                        backgroundPositionY: "40%",
                        backgroundPositionX: itemWidth - 15 + "px"
                    });
                })), d.attr("id", b.value), "auto" == itemWidth ? d.css({
                    height: itemHeight,
                    lineHeight: itemHeight + "px"
                }) : d.css({
                    width: itemWidth,
                    height: itemHeight,
                    lineHeight: itemHeight + "px"
                }), c.append(d), d.click(function() {
                    multiMode ? "current" == $(this).attr("class") ? $(this).removeClass("current") : $(this).addClass("current") : selectionStay ? ($select.find("li:[class=nocloseCurrent]").each(function() {
                        $(this).removeClass("nocloseCurrent");
                    }), $(this).addClass("nocloseCurrent")) : "current" == $(this).attr("class") ? $(this).removeClass("current") : ($select.find("li:[class=current]").each(function() {
                        $(this).removeClass("current");
                    }), $(this).addClass("current")), setCurrent();
                });
            }), c.append('<div class="clear"></div>'), 0 == enabled && $select.mask(uncompile(quiLanguage.filter.disabledMessage), 0, !1, "#ffffff"), 
            "-1" != selectedValue) {
                if (e = "", f = "", 1 == selectionStay) $select.find("li").each(function() {
                    $(this).attr("id") == selectedValue && ($(this).addClass("nocloseCurrent"), e = $(this).attr("id"), 
                    f = $(this).text());
                }); else {
                    for (g = selectedValue.split(","), h = 0; h < g.length; h++) $select.find("li").each(function() {
                        $(this).attr("id") == g[h] && ($(this).addClass("current"), e = e + $(this).attr("id") + ",", 
                        f = f + $(this).text() + ",");
                    });
                    e.length > 0 && (e = e.substring(0, e.length - 1)), f.length > 0 && (f = f.substring(0, f.length - 1));
                }
                $select.attr("relText", f), $select.attr("relValue", e), $hidden.val(e);
            } else 1 == selectionStay ? (i = $select.find("li").eq(0), i.addClass("nocloseCurrent"), 
            $select.attr("relText", i.text()), $select.attr("relValue", i.attr("id")), $hidden.val(i.attr("id"))) : ($select.attr("relText", ""), 
            $select.attr("relValue", ""), $hidden.val(""));
            $select.attr("finished", "true");
        }
    }
    function setCurrent() {
        var c, a = "", b = "";
        selectionStay ? (c = $select.find("li:[class=nocloseCurrent]"), a = c.attr("id"), 
        b = c.text()) : ($select.find("li:[class=current]").each(function() {
            a = a + $(this).attr("id") + ",", b = b + $(this).text() + ",";
        }), a.length > 0 && (a = a.substring(0, a.length - 1)), b.length > 0 && (b = b.substring(0, b.length - 1))), 
        $select.attr("relText", b), $select.attr("relValue", a), $hidden.val(a), $select.trigger("change", a);
    }
    var $parentThemeDom, selectionStay, filterWidth, $hidden, dataRoot, multiMode, showInfo, showTip, enabled, selectedValue, paramsStr, paramsObj, dataObj, urlStr, dataStr, dataObj2, dataType, $select = $(obj), itemWidth = 100, itemHeight = 22, defaultFilterItemWidth = 0, defaultFilterItemHeight = 0;
    if (splitMode || ($parentThemeDom = $(window.top.document.getElementById("theme")), 
    null != $parentThemeDom.attr("defaultFilterItemWidth") && (defaultFilterItemWidth = Number($parentThemeDom.attr("defaultFilterItemWidth"))), 
    null != $parentThemeDom.attr("defaultFilterItemHeight") && (defaultFilterItemHeight = Number($parentThemeDom.attr("defaultFilterItemHeight")))), 
    selectionStay = !1, ("true" == $select.attr("selectionStay") || 1 == $select.attr("selectionStay")) && (selectionStay = !0), 
    $select.attr("itemWidth") ? itemWidth = "auto" == $select.attr("itemWidth") ? selectionStay ? "auto" : 100 : Number($select.attr("itemWidth")) : 0 != defaultFilterItemWidth && (itemWidth = defaultFilterItemWidth), 
    $select.attr("itemHeight") ? itemHeight = Number($select.attr("itemHeight")) : 0 != defaultFilterItemHeight && (itemHeight = defaultFilterItemHeight), 
    filterWidth = 0, $select.attr("filterWidth") && (filterWidth = Number($select.attr("filterWidth")), 
    $select.width(filterWidth)), $hidden = setupHidden(), dataRoot = "list", $select.attr("dataRoot") && (dataRoot = $select.attr("dataRoot")), 
    multiMode = !1, ("true" == $select.attr("multiMode") || 1 == $select.attr("multiMode")) && (multiMode = !0), 
    1 == selectionStay && (multiMode = !1), showInfo = !1, ("true" == $select.attr("showInfo") || 1 == $select.attr("showInfo")) && (showInfo = !0), 
    showTip = !1, ("true" == $select.attr("showTip") || 1 == $select.attr("showTip")) && (showTip = !0), 
    enabled = !0, $(obj).attr("disabled") && (enabled = "false" == $(obj).attr("disabled") || 0 == $(obj).attr("disabled") ? !0 : !1), 
    selectedValue = "-1", null != $select.attr("selectedValue") && (selectedValue = $select.attr("selectedValue")), 
    paramsStr = $select.attr("params")) try {
        paramsObj = JSON.parse(paramsStr);
    } catch (e) {
        paramsObj = [], alert(uncompile(quiLanguage.filter.paramErrorMessage));
    } else paramsObj = [];
    if (dataObj = "", urlStr = $select.attr("url"), dataStr = $select.attr("data"), 
    dataObj2 = $select.data("data")) 1 == $select.attr("groupMode") || "true" == $select.attr("groupMode") ? createGroup($select, dataObj2) : createOptions($select, dataObj2); else if (dataStr) {
        try {
            dataObj = JSON.parse(dataStr);
        } catch (e) {
            dataObj = "", alert(uncompile(quiLanguage.filter.dataErrorMessage));
        }
        $select.data("data", dataObj), 1 == $select.attr("groupMode") || "true" == $select.attr("groupMode") ? createGroup($select, dataObj) : createOptions($select, dataObj);
    } else urlStr && (dataType = "json", $select.attr("dataType") && (dataType = $select.attr("dataType")), 
    $.ajax({
        url: $select.attr("url"),
        dataType: dataType,
        data: paramsObj,
        error: function() {
            alert(uncompile(quiLanguage.filter.urlErrorMessage));
        },
        success: function(data) {
            var myData;
            myData = "text" == dataType ? eval("(" + data + ")") : data, $select.data("data", myData), 
            dataObj = myData, 1 == $select.attr("groupMode") || "true" == $select.attr("groupMode") ? createGroup($select, dataObj) : createOptions($select, dataObj);
        }
    }));
};